package com.serviceprovider.business.module.sp.contact.controller;

//~--- non-JDK imports --------------------------------------------------------

import com.serviceprovider.business.module.admin.user.services.dao.interfaces.IUserService;
import com.serviceprovider.business.module.user.model.forms.ViewUserForm;
import com.serviceprovider.business.utility.RequestConstants;
import com.serviceprovider.business.utility.SendMail;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

//~--- JDK imports ------------------------------------------------------------

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author mrduongnv@gmail.com
 *
 */
@Controller
public class ContactSPController {

    /**
     * Added by NehaSiroya
     *
     * @param sess
     * @return
     */
    @Autowired
    IUserService userService;

    @RequestMapping(value = RequestConstants.ContactRequests.SP_CONTACTUS)
    public ModelAndView contactSP(HttpSession sess) {
        ModelAndView mav = new ModelAndView(RequestConstants.ContactRequests.VIEW_SP_CONTACTUS);

        return mav;
    }

    /**
     * Added by Umme Essa
     *
     * @param sess
     * @return
     */
    @RequestMapping(
        value  = RequestConstants.ContactRequests.CONTACTUS,
        method = RequestMethod.POST
    )
    public ModelAndView contactSPSubmit(HttpSession sess, HttpServletRequest request) {
        SendMail sendMail = new SendMail();

        sendMail.setSubject(request.getParameter("subject"));
        sendMail.setMessage(request.getParameter("message"));
        sendMail.setFrom(userService.getUserConnected().getEmail());

        try {
            sendMail.send();
        } catch (Exception e) {
            e.printStackTrace();
        }

        ModelAndView mav = new ModelAndView(RequestConstants.ContactRequests.VIEW_SP_CONTACTUS_DONE);

        return mav;
    }
}



